<?php
mysql_connect("127.0.0.1","root","sd2013");
mysql_select_db("mathRomp");

$newTime = $_REQUEST['newTime'];
$userId = $_REQUEST['userId'];

//Get user's fastest time
$q1=mysql_query("SELECT fastestTime FROM `Users` WHERE userId=".$userId."");
while($e=mysql_fetch_assoc($q1)){
  $output=$e;
}
$fastestTime = json_decode(json_encode($output))->{'fastestTime'};
print($fastestTime);

//Update fastest time if necessary
if($fastestTime > $newTime){
  $q2=mysql_query("UPDATE `Users` SET `fastestTime`=".$newTime." WHERE userId=".$userId."");
  while($f=mysql_fetch_assoc($q2)){
    $output1[]=$f;
  }
  print(json_encode($output1));
}
?>